package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TbViolation;
import com.ruoyi.system.service.ITbViolationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 违章信息Controller
 * 
 * @author ruoyi
 * @date 2025-04-21
 */
@RestController
@RequestMapping("/system/violation")
public class TbViolationController extends BaseController
{
    @Autowired
    private ITbViolationService tbViolationService;

    /**
     * 查询违章信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:violation:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbViolation tbViolation)
    {
        startPage();
        List<TbViolation> list = tbViolationService.selectTbViolationList(tbViolation);
        return getDataTable(list);
    }

    /**
     * 导出违章信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:violation:export')")
    @Log(title = "违章信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbViolation tbViolation)
    {
        List<TbViolation> list = tbViolationService.selectTbViolationList(tbViolation);
        ExcelUtil<TbViolation> util = new ExcelUtil<TbViolation>(TbViolation.class);
        util.exportExcel(response, list, "违章信息数据");
    }

    /**
     * 获取违章信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:violation:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbViolationService.selectTbViolationById(id));
    }

    /**
     * 新增违章信息
     */
    @PreAuthorize("@ss.hasPermi('system:violation:add')")
    @Log(title = "违章信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbViolation tbViolation)
    {
        return toAjax(tbViolationService.insertTbViolation(tbViolation));
    }

    /**
     * 修改违章信息
     */
    @PreAuthorize("@ss.hasPermi('system:violation:edit')")
    @Log(title = "违章信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbViolation tbViolation)
    {
        return toAjax(tbViolationService.updateTbViolation(tbViolation));
    }

    /**
     * 删除违章信息
     */
    @PreAuthorize("@ss.hasPermi('system:violation:remove')")
    @Log(title = "违章信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbViolationService.deleteTbViolationByIds(ids));
    }
}
